<?php

namespace App\Http\Controllers;

use App\Models\Carousel;
use App\Requests\YouzanApiRequest;
use App\Resources\CarouselResource;
use App\Services\YouzanApiService;

class YouzanController extends Controller
{
    protected $youzanApiService;

    public function __construct(YouzanApiService $youzanApiService)
    {
        $this->youzanApiService = $youzanApiService;
    }

    public function getCarousels()
    {
        $carousels = Carousel::where('status', 1)->get();
        return CarouselResource::collection($carousels);
    }

    public function getItemsOnsale(YouzanApiRequest $request)
    {
        $page = $request->get('page') ?? 1;
        $page_size = $request->get('page_size') ?? 40;
        $query = $request->get('query') ?? '';
        $order_by = $request->get('order_by') ?? '';
        $tag_id = $request->get('tag_id') ?? null;
        $update_time_start = $request->get('update_time_start') ?? null;
        $update_time_end = $request->get('update_time_end') ?? null;
        $response = $this->youzanApiService->itemOnsale($page_size, $page, $query, $order_by, $tag_id, $update_time_end, $update_time_start);
        return response()->json($response);
    }
}